package memberrewards.entities;

import java.util.ArrayList;
import java.util.Collection;
import java.util.StringTokenizer;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;

@Entity
public class BonusOffer {

	@Id
	private String offerId;
	private String offerType;
	private String eligibleMerchants;
	private String description;
	private String eligibleTiers;
	@Transient
	private Collection<String> tierList;

	public BonusOffer(String offerId, String offerType, String eligibleMerchants, String description,String eligTiers){
		this.offerId = offerId;
		this.offerType = offerType;
		this.eligibleMerchants = eligibleMerchants;
		this.description = description;
		setEligibleTiers(eligTiers);
	}
	
	public String getOfferId() {
		return offerId;
	}

	public void setOfferId(String offerId) {
		this.offerId = offerId;
	}

	public String getOfferType() {
		return offerType;
	}

	public void setOfferType(String offerType) {
		this.offerType = offerType;
	}

	public String getEligibleMerchants() {
		return eligibleMerchants;
	}

	public void setEligibleMerchants(String eligibleMerchants) {
		this.eligibleMerchants = eligibleMerchants;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getEligibleTiers() {
		return eligibleTiers;
	}

	public void setEligibleTiers(String eligTiers) {
		this.eligibleTiers = eligTiers;
		populateTierList();
	}
	private void populateTierList(){
		if(getEligibleTiers()!=null){
			this.tierList= new ArrayList<String>();
			StringTokenizer tokenizer= new StringTokenizer(getEligibleTiers(),",");
			String tier=null;
			while(tokenizer.hasMoreTokens()){
				tier=tokenizer.nextToken();
				tierList.add(tier);
			}
		}
	}

	public Collection<String> getTierList() {
		if(this.tierList==null){
			populateTierList();
		}
		return tierList;
	}
	
	

}
